#include "stdafx.h"
#include "Cpu.h"
#include "FirefoxHandler.h"
#include <future>

Cpu::Cpu()
{
	setOn("parseError", [](QVariantMap) {});
}

Cpu::~Cpu()
{

}

void Cpu::setOn(const QString &type, TaskProcessFunctionType func)
{
	tasks.emplace(type.toStdString(), func);
}

void Cpu::onMessage(const QString &type, const QVariantMap &args)
{
	TaskProcessFunctionType func = tasks.at(type.toStdString());

	std::async([=]()
	{
		func(args);
	});
}

Cpu * Cpu::instance()
{
	if (_instance == nullptr)
		_instance = new Cpu;
	return _instance;
}

Cpu * Cpu::_instance = nullptr;
